package org.cs2340.jellybeanwms.views;

import org.cs2340.jellybeanwms.R;
import org.cs2340.jellybeanwms.model.InMemoryModel;
import org.cs2340.jellybeanwms.presenters.EnterPersonPresenter;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

/**
 * Startup activity that gets a persons information
 * 
 * @author Robert
 *
 */
public class EnterPersonActivity extends Activity implements IEnterPersonView {
	
	/** The presenter for this activity */
    private EnterPersonPresenter myPresenter;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_enter_person);
		myPresenter = new EnterPersonPresenter(this, new InMemoryModel());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		//getMenuInflater().inflate(R.menu.activity_enter_person, menu);
		return true;
	}
	
	/**
	 * Button handler for the accept button
	 * 
	 * @param source not used
	 */
	public void onAcceptClick(View source) {
		String name = getNameField().getText().toString();
		String uid = getUidField().getText().toString();
		String email = getEmailField().getText().toString();
		myPresenter.onAddPersonClick(name, uid, email);
	}
	
	private EditText getNameField()     {
        return (EditText) findViewById(R.id.editName);
	}

	private EditText getUidField()     {
        return (EditText) findViewById(R.id.editUid);
	}
	
	private EditText getEmailField()     {
        return (EditText) findViewById(R.id.editEmail);
	}
	
	/**
	 * Button handler for the cancel button
	 * 
	 * @param v not used
	 */
	public void onCancelClick(View v) {
		myPresenter.onCancelAddPersonClick();
	}

	@Override
	public void advance() {
		//create an intent (a request for phone OS to do something)
		Intent intent = new Intent(this, PersonListingActivity.class);
		//now pass that to the phone OS and ask to start it
		startActivity(intent);
	}
}
